package com.itheima.demo;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("hello")
//@PreAuthorize("hasRole('ROLE_ADMIN')")
public class HelloController {

    @RequestMapping("demo1")
    public String demo1(HttpSession session){
        System.out.println("demo1方法请求转发");

        String name = (String) session.getAttribute("name");
        System.out.println(name);

        return "forward:/a.html";
    }

    @RequestMapping("demo2")
    public String demo2(){
        System.out.println("demo2方法请求重定向");
        return "redirect:/a.html";
    }


    @PreAuthorize("hasAuthority('add')")
    //@PreAuthorize("hasAnyAuthority('add','update')")

    @RequestMapping("demo3")
    public String demo3(HttpSession session){
        System.out.println("demo3方法请求重定向");
        session.setAttribute("name","wangwu");
        return "redirect:/a.html";
    }
}
